home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / VCal / EntryDialog.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  6.4 KB  |  237 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18.  
  19. #include "EntryDialog.h"
  20. #include "Entry.h"
  21. #include <Vk/VkPrefItem.h>
  22. #include "DayView.h"
  23. #include "Utils.h"
  24. #include "Preferences.h"
  25. #include <Vk/VkWarningDialog.h>
  26.  
  27. #include <Xm/Form.h>
  28. #include <Xm/LabelG.h>
  29. #include <Xm/PushB.h>
  30. #include <Xm/SeparatoG.h>
  31. #include <Xm/RowColumn.h>
  32.  
  33. static int count;
  34. static Arg args[10];
  35.  
  36. void EntryDialog::kind_stub(Widget w, XtPointer client_data, XtPointer)
  37. {
  38.   EntryDialog *obj = (EntryDialog *) client_data;
  39.   
  40.   obj->newKind(w);
  41. }
  42.  
  43. /**********************************************************************/
  44.  
  45. EntryDialog::EntryDialog(Entry *e, DayView *o, const char *name) : VkPrefDialog(name)
  46. {
  47.   owner = o;
  48.   _entry = e;
  49.   
  50.   list = NULL;
  51.   
  52.   list      = new VkPrefList("entryAttributes");
  53.   label     = new VkPrefLabel("label");
  54.   separator = new VkPrefSeparator("separator");
  55.   group     = new VkPrefGroup("group", False, True);
  56.   kind      = new VkPrefOption("kind", entryKindCount);
  57.   annotate  = new VkPrefToggle("annotate");
  58.   notifyPopup = new VkPrefToggle("notifyPopup", True);
  59.   notifyBell = new VkPrefToggle("notifyBell", True);
  60.   notifyMail = new VkPrefToggle("notifyMail", True);
  61.   notifyCommand = new VkPrefText("notifyCommand", 40);
  62.   advance   = new VkPrefText("advance");
  63.   repeat    = new VkPrefText("repeatEnd");
  64.   
  65.   group->addItem(kind);
  66.   group->addItem(annotate);
  67.   group->addItem(notifyPopup);
  68.   group->addItem(notifyBell);
  69.   group->addItem(notifyMail);
  70.   group->addItem(notifyCommand);
  71.   group->addItem(advance);
  72.   group->addItem(repeat);
  73.   list->addItem(label);
  74.   list->addItem(separator);
  75.   list->addItem(group);
  76.   setItem(list);
  77.  
  78.   updateDisplay();
  79. }
  80.  
  81. Widget EntryDialog::createDialog(Widget parent)
  82. {
  83.   int each;
  84.   XmString xs;
  85.   char str[256], *cstr, *p;
  86.   
  87.   Widget dialog =  VkPrefDialog::createDialog(parent);
  88.   
  89.   formatDate(_entry->day(), _entry->month(), _entry->year(), str);
  90.   strcat(str, ", ");
  91.   formatTime(_entry->start() / 60, _entry->start() % 60,
  92.          thePreferences->clock24(), str+strlen(str));
  93.   strcat(str, ":  ");
  94.   cstr = strdup(_entry->text());
  95.   if (p = strchr(cstr, '\n')) {
  96.     *p = '\0';
  97.     strcat(str, cstr);
  98.     strcat(str, "...");
  99.   } else {
  100.     strcat(str, cstr);
  101.   }
  102.   xs = XmStringCreateSimple(str);
  103.   count = 0;
  104.   XtSetArg(args[count], XmNlabelString, xs);  count++;
  105.   XtSetValues(label->baseWidget(), args, count);
  106.   XmStringFree(xs);
  107.   free(cstr);
  108.   for (each=0; each<entryKindCount; each++) 
  109.     {
  110.       kind->setLabel(each, entryKindList[each].string);
  111.       XtAddCallback(kind->getButton(each), XmNactivateCallback,
  112.             EntryDialog::kind_stub, (XtPointer) this);
  113.     }
  114.   
  115.   return dialog;
  116. }
  117.  
  118. /**********************************************************************/
  119.  
  120. void EntryDialog::apply(Widget, XtPointer)
  121. {
  122.   doApply();
  123. }
  124.  
  125. void
  126. EntryDialog::updateDisplay()
  127. {
  128.   char str[256];
  129.   int each;
  130.   RepeatingEntry *rentry;
  131.   
  132.   annotate->setValue(_entry->annotate());
  133.   notifyPopup->setValue(_entry->notifyPopup());
  134.   notifyBell->setValue(_entry->notifyBell());
  135.   notifyMail->setValue(_entry->notifyMail());
  136.   notifyCommand->setValue(_entry->notifyCommand());
  137.   advance->setValue(_entry->alarmAdvance());
  138.   for (each=0; each<entryKindCount; each++) {
  139.     if (entryKindList[each].kind == _entry->kind()) {
  140.       kind->setValue(each);
  141.       break;
  142.     }
  143.   }
  144.   if (_entry->repeating()) {
  145.     rentry = (RepeatingEntry *) _entry;
  146.     formatDate(rentry->repeatEndDay(), rentry->repeatEndMonth(),
  147.            rentry->repeatEndYear(), str);
  148.     repeat->setValue(str);
  149.     repeat->activate();
  150.   } else {
  151.     repeat->setValue("");
  152.     repeat->deactivate();
  153.   }
  154. }
  155.  
  156. Boolean
  157. EntryDialog::doApply()
  158. {
  159.   char *str;
  160.   int day, month, year;
  161.   Entry *nentry;
  162.   Boolean result;
  163.   EntryKind entryKind;
  164.   
  165.   list->updateValue();
  166.   result = True;
  167.   entryKind = entryKindList[kind->getValue()].kind;
  168.   if (entryKind != _entry->kind() &&
  169.       _entry->repeating() && entryKind == E_single) {
  170.     nentry = new Entry();
  171.     nentry->setDate(_entry->day(), _entry->month(), _entry->year());
  172.     nentry->setTime(_entry->start(), _entry->length()); 
  173.     nentry->setText(_entry->text());
  174.     _entry = nentry;
  175.   } else if (entryKind != _entry->kind() &&
  176.          !_entry->repeating() && entryKind != E_single) {
  177.     nentry = new RepeatingEntry();
  178.     nentry->setDate(_entry->day(), _entry->month(), _entry->year());
  179.     nentry->setTime(_entry->start(), _entry->length());
  180.     nentry->setText(_entry->text());
  181.     _entry = nentry;
  182.   }
  183.   _entry->setKind(entryKind);
  184.   _entry->setAnnotate(annotate->getValue());
  185.   _entry->setNotifyPopup(notifyPopup->getValue());
  186.   _entry->setNotifyBell(notifyBell->getValue());
  187.   _entry->setNotifyMail(notifyMail->getValue());
  188.   _entry->setNotifyCommand(notifyCommand->getValue());
  189.   if (_entry->setAlarmAdvance(advance->getValue())) {
  190.     advance->setValue(_entry->alarmAdvance());
  191.   } else {
  192.     theWarningDialog->post("Illegal alarm advance notice value.", NULL, this);
  193.     result = False;
  194.   }
  195.   if (_entry->repeating()) {
  196.     str = repeat->getValue();
  197.     if (parseDate(str, &day, &month, &year)) {
  198.       ((RepeatingEntry *) _entry)->setRepeatEnd(day, month, year);
  199.     } else {
  200.       theWarningDialog->post("Couldn't parse repeat end date.", NULL, this);
  201.       result = False;
  202.     }
  203.     XtFree(str);
  204.   }
  205.   updateDisplay();
  206.   owner->entryChanged(this);
  207.   return result;
  208. }
  209.  
  210. void
  211. EntryDialog::newKind(Widget w)
  212. {
  213.   int each;
  214.   Entry test;
  215.   
  216.   for (each=0; each<entryKindCount; each++) {
  217.     if (kind->getButton(each) == w) {
  218.       test.setKind(entryKindList[each].kind);
  219.       if(test.repeating())
  220.     repeat->activate();
  221.       else
  222.     repeat->deactivate();
  223.     }
  224.   }
  225. }
  226.  
  227. /**********************************************************************/
  228.  
  229. EntryDialog::~EntryDialog()
  230. {
  231.   if (list) {
  232.     list->deleteChildren();
  233.     delete list;
  234.   }
  235. }
  236.  
  237.